package pinboard.dataLayer.potocol.op;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import pinboard.dataLayer.ByteArrayConvert;
import pinboard.dataLayer.RefBag;
import pinboard.dataLayer.binPack.DefaultBinSerializer;
import pinboard.dataLayer.binPack.IBinSerializer;
import pinboard.dataLayer.potocol.Guid;


public class GuidBinSerializer extends DefaultBinSerializer {

    @Override
    public byte[] toBytes(Object input) {
        if (input == null) {
            return new byte[16];
        } else {
            Guid g = (Guid) input;
            return g.toByteArray();
        }
    }

    @Override
    public Object toObject(byte[] input, RefBag<Integer> offset) {
        byte[] bytes = new byte[16];
        System.arraycopy(input, offset.data, bytes, 0, bytes.length);
        offset.data = offset.data + 16;
        return new Guid(bytes);
    }

    @Override
    public Object[] toArray(byte[] input, RefBag<Integer> offset) {
        return super.toArray(input, offset, Guid.class);
    }
}
